import createVueRouter from '@/router/otherFunc'
import {PathAndComponent} from '@/router/dynamic'
//这里的数据未来是要放到数据库中的，所以不能写死
import {mainRoutes} from "@/router/mainRoutes";
import store from "@/store";


mainRoutes[0].children.push(...PathAndComponent)
const router = createVueRouter({
    mode: 'history',
    routes: mainRoutes
})
router.addRoutes([{
        path: "*",
        redirect: "/404",
    }, {
        name: '404',
        path: '/404',
        component: () => import('@/views/404.vue')
    }]
)

router.beforeEach(async (to, from, next) => {
    next()
})
router.afterEach((to, from) => {
    store.commit('_setMenu', PathAndComponent)
    document.title = '小程序后台管理'
    to.name !== null ? document.title = `${to.name} - ${document.title}` : void 0
})

export default router
